<template>
  <el-dialog width="1200px" :title="$t('m.otherstore.storagecode')+':'+$t('m.in.check')" :visible.sync="popupVisible" :before-close="close">

    <!-- storageBasicContent start -->
    <storageBasicContent ref="content" v-bind="$attrs"></storageBasicContent>
    <!-- storageBasicContent end -->

    <!-- tool start -->
    <el-form ref="table" :model="review" label-width="120px">
      <el-row>
        <el-col :span="24" align="left">
          <el-form-item :label="$t('m.in.result')+':'">
            <el-radio v-model="review.state" :label="3" :disabled="!isReview">{{$t('m.in.pass')}}</el-radio>
            <el-radio v-model="review.state" :label="2" :disabled="!isReview">{{$t('m.in.state2')}}</el-radio>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item :label="$t('m.notice.opinion')+':'" prop="remark">
            <el-input type="textarea" v-model="review.auditopinion" :rows="2" maxlength="100" :disabled="!isReview"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <!-- tool end -->
    <el-row>
      <el-col :span="24" :align="!isReview?'center':'right'">
        <el-button type="primary" @click="save" v-if="isReview" :loading="btnLoading">{{$t('m.otherstore.confirm')}}</el-button>
        <el-button @click="close">{{$t('m.close')}}</el-button>
      </el-col>
    </el-row>
  </el-dialog>
</template>
<script>
import storageBasicContent from './storage-basic-content'
export default {
  name:'storage-review-popup',
  props:['popupVisible'],
  inject:{
    getReviewState:{
      type:Function,
      default:()=>{}
    }
  },
  data(){
    return {
      review:{
        state:0,  //  审批结果
        auditopinion:'' // 审批意见
      },
      btnLoading:false // 控制按钮loading，防止重复提交
    }
  },
  computed:{
    isReview(){
      return this.getReviewState()
    }
  },
  mounted(){
    // console.log(this.$attrs.detail)
    this.review.state = this.$attrs.detail.state || 0
    this.review.auditopinion = this.$attrs.detail.auditopinion || ''
  },
  components:{storageBasicContent},
  methods:{
    close(){
      this.$emit('close')
    },
    save(){
      if(this.review.state===1) return this.callbackMessage(this.$t('m.choose')+this.$t('m.in.result'))
      let id = this.$attrs.detail.storageid
      let data = {...this.review,id}
      let options = {
        method:'post',
        url:`/otherstorage/check/${id}`,
        data
      }
      this.btnLoading = true
      this.$axios(options).then(({message})=> {
        this.btnLoading = false
        this.callbackMessage(message,'success')
        this.$emit('successCallback')
        this.close()
      }).catch(()=>{
        this.btnLoading = false
      })
    }
  }

}
</script>